﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Killboard.Models
{
    public class SlottedItems
    {
        public string[] keysOrder = new string[] { "hiPower", "medPower", "loPower", "rigSlot" };

        private Dictionary<string, List<ekbItemDrop>> itemsInSlot = new Dictionary<string, List<ekbItemDrop>>();

        public Dictionary<string, List<ekbItemDrop>> ItemsInSlot
        {
            get { return itemsInSlot; }
            set { itemsInSlot = value; }
        }

        public SlottedItems(IEnumerable<ekbItemDrop> items)
        {
            var itemList = from i in items
                           where i.CargoFlag == false
                           select i;

            foreach (ekbItemDrop item in itemList)
            {
                var fx = from x in item.invType.dgmTypeEffects
                         where x.dgmEffect.effectName.Contains("Power") || x.dgmEffect.effectName.Equals("rigSlot")
                         select x;

                //some "slotted" items are scripts.  need to handle them
                //for now, though, just ignore.
                if (fx.Count() > 0)
                {
                    string effectName = fx.First().dgmEffect.effectName;

                    if (!itemsInSlot.ContainsKey(effectName))
                    {
                        itemsInSlot.Add(effectName, new List<ekbItemDrop>());
                    }

                    itemsInSlot[effectName].Add(item);
                }                            
            }
        }

    }
}
